//
//  MsgFriendListCell.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/19.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "MsgFriendListCell.h"

@interface MsgFriendListCell()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *avatar_image_view;
@property (nonatomic, strong) UILabel *name_label;
@property (nonatomic, strong) UIButton *agree_button;
@property (nonatomic, strong) UIButton *refuse_button;

@end

@implementation MsgFriendListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self makeMsgFriendListCell];
        
    }
    return self;
}

- (void)makeMsgFriendListCell
{
    _bgView = [UIView new];
    _bgView.layer.cornerRadius = 5.0;
    [self.contentView addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(-5);
    }];
    
    _avatar_image_view = [UIImageView new];
    _avatar_image_view.layer.masksToBounds = YES;
    _avatar_image_view.layer.cornerRadius = 18;
    [_bgView addSubview:_avatar_image_view];
    [_avatar_image_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(6);
        make.bottom.mas_equalTo(-6);
        make.left.mas_equalTo(25);
        make.width.mas_equalTo(36);
    }];
    
    _agree_button = [UIButton new];
    _agree_button.layer.cornerRadius = 5.0;
    _agree_button.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    _agree_button.backgroundColor = RGB(4, 171, 82);
    [_agree_button setTitle:@"同意" forState:UIControlStateNormal];
    [_agree_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_agree_button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [_agree_button addTarget:self action:@selector(clickAgreeButton:) forControlEvents:UIControlEventTouchUpInside];
    [_bgView addSubview:_agree_button];
    [_agree_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.right.mas_equalTo(-15);
        make.width.mas_equalTo(60);
    }];
    
    _refuse_button = [UIButton new];
    _refuse_button.layer.cornerRadius = 5.0;
    _refuse_button.titleLabel.font = [UIFont systemFontOfSize:15.0f];
    _refuse_button.backgroundColor = RGB(213, 65, 41);
    [_refuse_button setTitle:@"拒绝" forState:UIControlStateNormal];
    [_refuse_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_refuse_button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [_bgView addSubview:_refuse_button];
    [_refuse_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
        make.right.mas_equalTo(_agree_button.mas_left).mas_offset(-15);
        make.width.mas_equalTo(60);
    }];
    
    _name_label = [UILabel new];
    _name_label.textColor = [UIColor blackColor];
    [_bgView addSubview:_name_label];
    [_name_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(_avatar_image_view.mas_right).mas_offset(25);
        make.right.mas_equalTo(_refuse_button.mas_left).mas_offset(-25);
    }];
    
}

- (void)loadData:(FriendModel *)friendModel index:(NSInteger)index
{
    if (index % 2 == 0) {
        _bgView.backgroundColor = RGB(245, 242, 242);
    }else{
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    
    [_avatar_image_view sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseIp,friendModel.friendInfo.avatar]]];
    
    _name_label.text = friendModel.friendInfo.username;
}

- (void)clickAgreeButton:(UIButton *)sender
{
    if (self.agreeBlock) {
        self.agreeBlock();
    } 
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
